<template>
    <div class="content-wrap">
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>单位名称</label>
            </div>
            <div class="equipment-right-select"
                 @click="selectType">
                <span>{{checkcompany.Name?checkcompany.Name:'请选择'}}</span>
                <i class="iconfont icon-jinru rightmsg"></i>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>开始时间</label>
            </div>
            <group>
                <datetime v-model="startTime"
                          @on-change="onPullingDown"></datetime>
            </group>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>结束时间</label>
            </div>
            <group>
                <datetime v-model="endTime"
                          @on-change="onPullingDown"></datetime>
            </group>
        </div>
        <h3>数量：{{listAllCount}}</h3>
        <noData v-if="listAllCount.length == 0"></noData>
        <div class="bscroll">
            <vue-better-scroll class="wrapper"
                               ref="scroll"
                               :scrollbar="scrollbarObj"
                               :pullDownRefresh="pullDownRefreshObj"
                               :pullUpLoad="pullUpLoadObj"
                               :startY="parseInt(startY)"
                               @pullingDown="onPullingDown"
                               @pullingUp="onPullingUp">
                <ul class="lists">
                    <li v-for="(item,index) in lists"
                        :key="index">
                        <router-link :to="{path:'/agreementDetail',query:{
                            id:item.Id
                        }}">
                            <div>
                                <h5>{{item.AgreementName}}</h5>
                                <p>{{item.SignDate?item.SignDate.split(' ')[0]:''}}</p>
                            </div>
                            <div class="status">
                                <x-icon type="ios-arrow-right"
                                        size="20"
                                        class="icon-right"
                                        fill="#999"></x-icon>
                            </div>
                        </router-link>
                    </li>
                </ul>
            </vue-better-scroll>
        </div>
        <myMenu></myMenu>
        <companyProp :companyPropShow="companyPropShow"
                     :selectCompany="selectCompany"></companyProp>
    </div>
</template>
<script>
import VueBetterScroll from 'vue2-better-scroll'
import formatDate from '@/utils/formatDate'
import myMenu from '@/commonComponents/menu'
import companyProp from '@/commonComponents/companyProp'
export default {
    name: 'electricianAgreement',
    data () {
        return {
            scrollbarObj: {
                fade: true
            },
            // 这个配置用于做下拉刷新功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启下拉刷新，可以配置顶部下拉的距离（threshold） 来决定刷新时机以及回弹停留的距离（stop）
            pullDownRefreshObj: true,
            // 这个配置用于做上拉加载功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启上拉加载，可以配置离底部距离阈值（threshold）来决定开始加载的时机
            pullUpLoadObj: {
                threshold: 0,
                txt: {
                    more: '加载更多',
                    noMore: '没有更多数据了'
                }
            },
            startY: 0, // 纵轴方向初始化位置
            startTime: `${formatDate().split('-')[0]}-${formatDate().split('-')[1]}-01`,
            endTime: formatDate(),
            userInfo: {},
            checkcompany: {
            }, //  单位名称
            lists: [],
            pageIndex: 0, // 当前页
            listAllCount: 0, // 总条数
            companyPropShow: false
        }
    },
    components: {
        VueBetterScroll,
        myMenu,
        companyProp
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo')) || {}
        this.checkcompany = {
            Name: this.userInfo.deptname,
            Id: this.userInfo.deptid
        }
        this.onPullingDown()
    },
    methods: {
        onButtonClick (type) {
            alert('on button click ' + type)
        },
        handleEvents (type) {
            console.log('event: ', type)
        },
        selectType () {
            this.companyPropShow = true
        },
        handleSubmit () {
            this.$vux.loading.show({
                text: '加载中...'
            })
            let params = {
                'allowPaging': false,
                'business': 'getConstructionEleManPro',
                'data': {
                    'End': this.endTime, // -- - 结束时间
                    'Start': this.startTime, // -- - 开始时间
                    'departId': this.checkcompany.Id //  -- - 单位id
                },
                'pageIndex': this.pageIndex,
                'pageSize': 20,
                'tokenId': '',
                'userId': this.userInfo.userid
            }
            this.$axiosAjax.getConfigJson(params).then((res) => {
                if (res.data.code === 0) {
                    this.listAllCount = res.data.count
                    this.lists = this.lists.concat(res.data.data)
                    if (this.lists.length < this.listAllCount) {
                        this.$refs.scroll.forceUpdate(true)
                    } else {
                        this.$refs.scroll.forceUpdate(false)
                    }
                }
            }).catch(() => {

            }).finally(() => {
                this.$vux.loading.hide()
            })
        },
        onPullingUp () {
            this.pageIndex++
            this.handleSubmit()
        },
        onPullingDown () {
            this.pageIndex = 0
            this.lists = []
            this.handleSubmit()
        },
        selectCompany (item) {
            this.companyPropShow = false
            this.checkcompany = {
                Name: item.Name,
                Id: item.Id
            }
            this.onPullingDown()
        }
    }
}
</script>
<style lang="less" scoped>
.content-wrap {
    height: 100%;
    h3 {
        height: 40px;
        line-height: 40px;
        color: #999;
        font-size: 14px;
        background: #ebeef2;
        padding-right: 20px;
        text-align: right;
    }
    .bscroll {
        position: absolute;
        top: 205px;
        left: 0;
        right: 0;
        bottom: 0;
        overflow: hidden;
    }
    .lists {
        padding-left: 20px;
        a {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 14px 20px 14px 0;
            border-bottom: 1px solid #efeff4;
        }
        h5 {
            line-height: 18px;
            color: #333;
            font-size: 14px;
        }
        p {
            font-size: 14px;
            color: #999;
            line-height: 18px;
        }
        .status {
            display: flex;
            align-items: center;
            span {
                font-size: 12px;
            }
            .orange {
                color: #fe7234;
            }
            .blue {
                color: #2369ff;
            }
            .green {
                color: #13bc83;
            }
            .red {
                color: #ff0100;
            }
        }
    }
}
</style>
